<?php
namespace App\Http\Controllers\Admin;

use App\Service\Admin\StaffService;
use Illuminate\Http\Request;

class LoginController extends BaseController
{
    //登录
    public function dologin(Request $request)
    {
        $uname = $request->post('uname', '');
        $upwd = $request->post('passwd', '');
        $res = StaffService::dologin($uname, $upwd);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //获取权限
    public function leftMenu(Request $request)
    {
        $uid = $request->post('uid', 0);
        $role_id = $request->post('role_id', 0);
        $res = StaffService::leftMenu($uid, $role_id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //过期设置
    public function configSet(Request $request)
    {
        $item = $request->post('item', '');
        $period = $request->post('period', '');
        $config = file_get_contents('config.json');
        $res = json_decode($config, true);
        if (!$res) {
            return self::toJson(-2, '没有配置');
        }
        if ($item) {
            $res['item_name'] = $item;
        }
        if ($period) {
            $res['period'] = date('YmdHis', strtotime($period));
        }
        file_put_contents('config.json', json_encode($res, 384));
        return self::toJson();
    }
}